#!/usr/bin/env python
#coding:utf-8
 
from wsgiref.simple_server import make_server

def index():
    data = open('html/index.html').read()
    return data

def dali():
    data = open('html/dali.html').read()
    return data

url_list=[
    ('/index/',index),
    ('/dali/',dali)
]

def RunServer(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    #根据URL不同，返回不同的字符串
    #1、获取URL
    #2、根据URL不同做不同的响应
    request_url=environ["PATH_INFO"]
    # print request_url
    # if request_url == "/home/index"
    #   return "haojie"
    # elif request_url=="/dali":
    #   return "dali"
    #else:
    #   return "404"
    for url in url_list:
        if request_url == url[0]:
            return url[1]()
    else:
        return "404"
 
if __name__ == '__main__':
    httpd = make_server('', 8000, RunServer)
    print "Serving HTTP on port 8000..."
    httpd.serve_forever()